﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Honestysoft.Financing.DataAccess;
using Honestysoft.Financing.Model;
using System.Data.Common;
using Honestysoft.BaseObject;

namespace Honestysoft.Financing.BusinessLogic
{
    public class Audit
    {
            string _connectionStringName;
        /// <summary>
        /// 构造函数，使用指定的连接字符串
        /// </summary>
        /// <param name="connectionStringName">连接字符串名称</param>
            public Audit(string connectionStringName)
        {
            _connectionStringName = connectionStringName;
        }

        /// <summary>
        /// 得到资料接收表(回执)
        /// </summary>
        /// <param name="projectCategory"></param>
        /// <param name="projectId"></param>
        /// <param name="projectName"></param>
        /// <param name="contractCategory"></param>
        /// <param name="code"></param>
        /// <param name="name"></param>
        /// <param name="id"></param>
        /// <param name="pageSize"></param>
        /// <param name="currentPageIndex"></param>
        /// <param name="pageCount"></param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        public DataTable GetDocReceive(string projectCategory, string projectId, string projectName, string contractCategory, string code, string name, string id, int pageSize, int currentPageIndex, out int pageCount, out int recordCount)
        {
            DataTable dt= new Bu_DocReceive_DAL(_connectionStringName).GetDocReceive(projectCategory, projectId, projectName, contractCategory,
                code, name, id, pageSize, currentPageIndex, out pageCount, out recordCount);
            dt.Columns.Add("IsUse", typeof(bool));
            object obj = null;
            foreach (DataRow dr in dt.Rows)
            {
               obj= dr["IsRec"];
               if (obj == null || obj == DBNull.Value)
                {
                    dr["IsUse"] = false;
                }
                else
                {
                    dr["IsUse"] = Convert.ToBoolean(obj);
                }
            }
            return dt;
        }

        /// <summary>
        /// 得到资金申请批次
        /// </summary>
        /// <param name="batch"></param>
        /// <param name="status"></param>
        /// <param name="pageSize"></param>
        /// <param name="currentPageIndex"></param>
        /// <param name="pageCount"></param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        public DataTable GetBatchs(int? batch,string status, int pageSize, int currentPageIndex, out int pageCount, out int recordCount)
        {
            return new Bu_AuditBatch_DAL(_connectionStringName).GetBatchs(batch,status, pageSize, currentPageIndex, out pageCount, out recordCount);
        }
        /// <summary>
        /// 得到下一个批次号码
        /// </summary>
        /// <returns></returns>
        public int GetNextBatchNo()
        {
            return new Bu_AuditBatch_DAL(_connectionStringName).GetNextBatchNo();
        }
        /// <summary>
        /// 得到批次具有的合同
        /// </summary>
        /// <param name="batchID"></param>
        /// <returns></returns>
        public DataTable GetBatchContract(string batchID)
        {
            return new Bu_BatchContract_DAL(_connectionStringName).GetBatchContract(batchID);
        }
        /// <summary>
        /// 得到可导入的资料接收表
        /// </summary>
        /// <param name="arrFilterContractId"></param>
        /// <param name="projectName"></param>
        /// <param name="contractCategory"></param>
        /// <param name="code"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public DataTable GetCanSelectDocReceive(string[] arrFilterContractId, string projectName, string contractCategory, string code, string name)
        {
            return new Bu_DocReceive_DAL(_connectionStringName).GetCanSelectDocReceive(arrFilterContractId, projectName, contractCategory, code, name);
        }

        /// <summary>
        /// 得到批次具有的项目
        /// </summary>
        /// <returns></returns>
        public DataTable GetBatchProject()
        {
            return new Bu_AuditTable_DAL(_connectionStringName).GetBatchProject();
        }

        public DataTable GetBatchProject(string batchId)
        {
            return new Bu_AuditTable_DAL(_connectionStringName).GetBatchProject(batchId);
        }

        public DataTable GetBatchContract(string batchId, string projectId)
        {
            return new Bu_AuditTable_DAL(_connectionStringName).GetBatchContract(batchId, projectId);
        }
        /// <summary>
        /// 创建新的内部审核作业表
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="batchId"></param>
        /// <param name="contractId"></param>
        /// <param name="code"></param>
        /// <param name="curAmount"></param>
        /// <param name="conPerAmount"></param>
        /// <returns></returns>
        public bool CreateAuditTable(string userId, string batchId, string contractId, string code, decimal curAmount, decimal conPerAmount)
        {
            return new Bu_AuditTable_DAL(_connectionStringName).CreateAuditTable(userId, batchId, contractId, code, curAmount, conPerAmount);
        }
        /// <summary>
        /// 得到最大的批次ID
        /// </summary>
        /// <returns></returns>
        public string GetMaxBatchID()
        {
            return new Bu_AuditBatch_DAL(_connectionStringName).GetMaxBatchID();
        }
        /// <summary>
        /// 得到下一个内部审核表编号
        /// </summary>
        /// <param name="contractId"></param>
        /// <returns></returns>
        public string GetNextAuditCode(string contractId)
        {
            return new Bu_AuditTable_DAL(_connectionStringName).GetNextAuditCode(contractId);
        }
        /// <summary>
        /// 得到下一个回执编号
        /// </summary>
        /// <returns></returns>
        public string GetNextDocReceiveCode()
        {
            return new Bu_DocReceive_DAL(_connectionStringName).GetNextCode();
        }
        /// <summary>
        /// 得到批次导入的回执信息
        /// </summary>
        /// <param name="arrRecID"></param>
        /// <returns></returns>
        public DataTable GetDocReceives(string[] arrRecID)
        {
            return new Bu_BatchRec_DAL(_connectionStringName).GetDocReceives(arrRecID);
        }
        /// <summary>
        /// 得到批次数量
        /// </summary>
        /// <returns></returns>
        public int GetBatchCount()
        {
            return new Bu_AuditBatch_DAL(_connectionStringName).GetCount();
        }
        /// <summary>
        /// 得到完成的批次数量
        /// </summary>
        /// <returns></returns>
        public int GetCompleteBatchCount()
        {
            return new Bu_AuditBatch_DAL(_connectionStringName).GetCompleteCount();
        }
        /// <summary>
        /// 得到发改委返回的批次
        /// </summary>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <returns></returns>
        public DataTable GetBatchFGW(int from, int to)
        {
            return new Bu_AuditBatch_DAL(_connectionStringName).GetBatchFGW(from, to);
        }
        /// <summary>
        /// 根据批次得到回执
        /// </summary>
        /// <param name="batchID"></param>
        /// <returns></returns>
        public DataTable GetDocReceiveByBatchID(string batchID)
        {
            return new Bu_BatchRec_DAL(_connectionStringName).GetDocReceiveByBatchID(batchID);
        }

        /// <summary>
        /// 得到内部审核作业表
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Bu_AuditTable GetAuditTable(string id)
        {
            Bu_AuditTable obj = new Bu_AuditTable_DAL(_connectionStringName).SelectEntityByKey(id);
            if (obj.TableType != "A")
            {
                Bu_AuditTable_SplitPastTime_DAL splitPastDAL = new Bu_AuditTable_SplitPastTime_DAL(_connectionStringName);
                obj.Count_Split_PassTime_A = splitPastDAL.GetCountA(id);
                obj.Count_Split_PassTime_NA = splitPastDAL.GetCountNA(id);
                obj.Count_Split_CurOther = new Bu_AuditTable_SplitCurOther_DAL(_connectionStringName).GetCount(id);
            }
            obj.SummaryAmount = new Bu_AuditTable_Amount_DAL(_connectionStringName).SelectEntityByKey(id);
            obj.AuditCase = new Bu_AuditTable_Opinion_DAL(_connectionStringName).SelectEntityByKey(id);
            QueryParameters query = new QueryParameters();
            OrderParameters order = new OrderParameters();
            query.Add("TableID", id, QueryParameters.OperatorType.Equal);
            order.Add("TheYear");
            obj.YearPlans = new Bu_AuditTable_Plan_DAL(_connectionStringName).SelectEntitys(query, order);
            order = new OrderParameters();
            order.Add("ProjectSN");
            obj.CurOther_Split = new Bu_AuditTable_Split_DAL(_connectionStringName).SelectEntitys(query, order);
            order = new OrderParameters();
            order.Add("SortCode");
            obj.DOwners = new Bu_AuditTable_DOwner_DAL(_connectionStringName).SelectEntitys(query, order);
            
            obj.CurOther_C = new List<Bu_AuditTable_CurOther>();
            obj.CurOther_P = new List<Bu_AuditTable_CurOther>();
            obj.PastTime_C_A = new List<Bu_AuditTable_PastTime>();
            obj.PastTime_C_NA = new List<Bu_AuditTable_PastTime>();
            obj.PastTime_P_A = new List<Bu_AuditTable_PastTime>();
            obj.PastTime_P_NA = new List<Bu_AuditTable_PastTime>();
            order = new OrderParameters();
            order.Add("SortNo");
            obj.Invoices = new Bu_AuditTable_Invoice_DAL(_connectionStringName).SelectEntitys(query, order);

            DataTable dtCurOther = new Bu_AuditTable_CurOther_DAL(_connectionStringName).GetCurOther(id);
            DataTable dtPastTime = new Bu_AuditTable_PastTime_DAL(_connectionStringName).GetPassTimeAuditTable(id);

            Bu_AuditTable_CurOther other = null;
            foreach (DataRow dr in dtCurOther.Rows)
            {
                other = new Bu_AuditTable_CurOther();
                other.Amount_S = Convert.ToDecimal(dr["Amount_S"]);
                other.Amount_DocRec_S = Convert.ToDecimal(dr["Amount_DocRec_S"]);
                other.AuditTableCode = dr["Code"].ToString();
                other.ID = dr["ID"].ToString();
                other.OtherTableID = dr["OtherTableID"].ToString();
                other.SumCategory = dr["SumCategory"].ToString();
                other.TableID = dr["TableID"].ToString();
                other.TableNo = Convert.ToInt32(dr["TableNo"]);
                if (other.SumCategory == ((int)EnumItem.SumCategory.ByContract).ToString())
                {
                    obj.CurOther_C.Add(other);
                }
                else
                {
                    obj.CurOther_P.Add(other);
                }
            }
            if (obj.CurOther_C.Count == 1)
            {
                other = new Bu_AuditTable_CurOther();
                other.Amount_DocRec_S = 0;
                other.Amount_S = 0;
                other.AuditTableCode = "";
                other.ID = Honestysoft.BaseLibrary.Common.Guid.GetGuid();
                other.OtherTableID = obj.ID;
                other.SumCategory = ((int)EnumItem.SumCategory.ByContract).ToString();
                other.TableID = obj.ID;
                other.TableNo = 3;
                obj.CurOther_C.Add(other);
            }
            //本项目本期同时申请的数据必须加上自身
            other = new Bu_AuditTable_CurOther();
            other.Amount_DocRec_S = obj.Amount_DocRec_S;
            other.Amount_S = obj.Amount_S;
            other.AuditTableCode =obj.Code;
            other.ID = Honestysoft.BaseLibrary.Common.Guid.GetGuid();
            other.OtherTableID = obj.ID;
            other.SumCategory =((int)EnumItem.SumCategory.ByProject).ToString();
            other.TableID = obj.ID;
            other.TableNo =obj.TableNo;
            obj.CurOther_P.Insert(0, other);
            Bu_AuditTable_PastTime pastTime = null;
            if (obj.CurOther_P.Count < 6)
            {
                for (int i = obj.CurOther_P.Count; i < 6; i++)
                {
                    other = new Bu_AuditTable_CurOther();
                    other.Amount_DocRec_S = 0;
                    other.Amount_S = 0;
                    other.AuditTableCode = "";
                    other.ID = Honestysoft.BaseLibrary.Common.Guid.GetGuid();
                    other.OtherTableID = obj.ID;
                    other.SumCategory = ((int)EnumItem.SumCategory.ByProject).ToString();
                    other.TableID = obj.ID;
                    other.TableNo = 0;
                    obj.CurOther_P.Add(other);
                }
            }
            if (obj.CurOther_C.Count == 0)//如果没有，则默认留2笔
            {
                other = new Bu_AuditTable_CurOther();
                other.Amount_DocRec_S = 0;
                other.Amount_S =0;
                other.TableNo = 2;
                obj.CurOther_C.Add(other);
                other = new Bu_AuditTable_CurOther();
                other.Amount_S = 0;
                other.TableNo = 3;
                obj.CurOther_C.Add(other);
            }
            
            foreach (DataRow dr in dtPastTime.Rows)
            {
                pastTime = new Bu_AuditTable_PastTime();
                pastTime.AuditTableCode = dr["Code"].ToString();
                pastTime.ID = dr["ID"].ToString();
                pastTime.IsBF = Convert.ToBoolean(dr["IsBF"]);
                pastTime.PastTableID = dr["PastTableID"].ToString();
                pastTime.SumCategory = dr["SumCategory"].ToString();
                pastTime.TableID = dr["TableID"].ToString();
                if (pastTime.IsBF)
                {
                    pastTime.ActiveAmount = Convert.ToDecimal(dr["BFAmount"]);
                    pastTime.BFEndDate = Convert.ToDateTime(dr["BFDate"]);
                    if (pastTime.SumCategory == ((int)EnumItem.SumCategory.ByContract).ToString())
                    {
                        obj.PastTime_C_A.Add(pastTime);
                    }
                    else
                    {
                        obj.PastTime_P_A.Add(pastTime);
                    }
                }
                else
                {
                    pastTime.ActiveAmount = Convert.ToDecimal(dr["Amount_S"]);
                    if (pastTime.SumCategory == ((int)EnumItem.SumCategory.ByContract).ToString())
                    {
                        obj.PastTime_C_NA.Add(pastTime);
                    }
                    else
                    {
                        obj.PastTime_P_NA.Add(pastTime);
                    }
                }                
            }
            if (obj.PastTime_C_NA.Count < 5)
            {
                //未拨付不足5行时，补空行
                for (int i = obj.PastTime_C_NA.Count; i < 5; i++)
                {
                    pastTime = new Bu_AuditTable_PastTime();
                    pastTime.AuditTableCode = "";
                    pastTime.ID = Honestysoft.BaseLibrary.Common.Guid.GetGuid();
                    pastTime.IsBF = false;
                    pastTime.PastTableID = "";
                    pastTime.SumCategory = ((int)EnumItem.SumCategory.ByContract).ToString();
                    pastTime.TableID = obj.ID;
                    obj.PastTime_C_NA.Add(pastTime);
                }
            }
            ////如果没有未拨付，则新增一个空行
            //if (obj.PastTime_C_NA.Count == 0)
            //{
            //    pastTime = new Bu_AuditTable_PastTime();
            //    pastTime.AuditTableCode = "";
            //    pastTime.ID = Honestysoft.BaseLibrary.Common.Guid.GetGuid();
            //    pastTime.IsBF = false;
            //    pastTime.PastTableID = "";
            //    pastTime.SumCategory = ((int)EnumItem.SumCategory.ByContract).ToString();
            //    pastTime.TableID = obj.ID;
            //    obj.PastTime_C_NA.Add(pastTime);
            //}
            if (obj.PastTime_P_NA.Count < 5)
            {
                for (int i = obj.PastTime_P_NA.Count; i < 5; i++)
                {
                    pastTime = new Bu_AuditTable_PastTime();
                    pastTime.AuditTableCode = "";
                    pastTime.ID = Honestysoft.BaseLibrary.Common.Guid.GetGuid();
                    pastTime.IsBF = false;
                    pastTime.PastTableID = "";
                    pastTime.SumCategory = ((int)EnumItem.SumCategory.ByProject).ToString();
                    pastTime.TableID = obj.ID;
                    obj.PastTime_P_NA.Add(pastTime);
                }
            }
            return obj;
        }
        /// <summary>
        /// 保存内部审核作业表
        /// </summary>
        /// <param name="id"></param>
        /// <param name="buStatus"></param>
        /// <param name="docRecAmount"></param>
        /// <param name="amount"></param>
        /// <param name="tAmount_C_A"></param>
        /// <param name="amountHT"></param>
        /// <param name="isPD1"></param>
        /// <param name="isPD2"></param>
        /// <param name="isPD3"></param>
        /// <param name="isPD4"></param>
        /// <param name="isPD5"></param>
        /// <param name="isPD6"></param>
        /// <param name="isPD7"></param>
        /// <param name="isPD8"></param>
        /// <param name="isPD9"></param>
        /// <param name="isPD10"></param>
        /// <param name="pd1"></param>
        /// <param name="pd1Opinion"></param>
        /// <param name="pd2"></param>
        /// <param name="pd2Opinion"></param>
        /// <param name="isCD1"></param>
        /// <param name="isCD2"></param>
        /// <param name="isCD3"></param>
        /// <param name="isCD4"></param>
        /// <param name="isCD5"></param>
        /// <param name="isCD6"></param>
        /// <param name="isCD7"></param>
        /// <param name="isCD8"></param>
        /// <param name="isCD9"></param>
        /// <param name="cd"></param>
        /// <param name="cdOpinion"></param>
        /// <param name="isZD1"></param>
        /// <param name="isZD2"></param>
        /// <param name="isZD3"></param>
        /// <param name="isZD4"></param>
        /// <param name="zd"></param>
        /// <param name="zdOpinion"></param>
        /// <param name="forPPriceOpinion"></param>
        /// <param name="forPlanOpinion"></param>
        /// <param name="forLoanOpinion"></param>
        /// <param name="forCPriceOpinion"></param>
        /// <param name="forProgress"></param>
        /// <param name="forProgressOpinion"></param>
        /// <returns></returns>
        public bool SaveAuditTable(string id, string buStatus,decimal docRecAmount, decimal amount, decimal tAmount_C_A,decimal amountHT,
            bool isPD1, bool isPD2, bool isPD3, bool isPD4, bool isPD5, bool isPD6, bool isPD7, bool isPD8, bool isPD9, bool isPD10,
            string pd1, string pd1Opinion, string pd2, string pd2Opinion,
            bool isCD1, bool isCD2, bool isCD3, bool isCD4, bool isCD5, bool isCD6, bool isCD7, bool isCD8, bool isCD9,
            string cd, string cdOpinion,
            bool isZD1, bool isZD2, bool isZD3, bool isZD4,
            string zd, string zdOpinion,
            string forPPriceOpinion, string forPlanOpinion,
            string forLoanOpinion, string forCPriceOpinion,
            string forProgress, string forProgressOpinion)
        {
            //TODO:必须刷新公式计算过程及计算结果
            bool bRet = false;
            DbTransaction transaction = Honestysoft.BaseLibrary.Data.DatabaseProvider.GetDbTransaction(_connectionStringName);
            DbConnection connection = transaction.Connection;
            try
            {
                Bu_AuditTable_DAL dal1 = new Bu_AuditTable_DAL(_connectionStringName);
                if (buStatus == ((int)EnumItem.AuditTableStatus.FAppr).ToString())
                {
                    dal1.UpdateAuditTable_F(id, docRecAmount, amount, tAmount_C_A, amountHT, transaction);
                }
                else if (buStatus == ((int)EnumItem.AuditTableStatus.SAppr).ToString())
                {
                    dal1.UpdateAuditTable_S(id, docRecAmount, amount, tAmount_C_A, amountHT, transaction);
                }
                else
                {
                    dal1.UpdateAuditTable(id, docRecAmount, amount, tAmount_C_A, amountHT, transaction);
                }
                //如果审核金额及申请金额同时清0，则表示退回，必须更新回执也为0
                //同时，T=A+H必须修改，匹配关系及核算结果也需要修改
                if (docRecAmount == 0 && amount == 0)
                {
                    dal1.BackDocReceive(id, transaction);
                }
                Bu_AuditTable_Opinion_DAL dal2 = new Bu_AuditTable_Opinion_DAL(_connectionStringName);
                dal2.UpdateOpinion(id, isPD1, isPD2, isPD3, isPD4, isPD5, isPD6, isPD7, isPD8, isPD9, isPD10,
                     pd1, pd1Opinion, pd2, pd2Opinion,
                     isCD1, isCD2, isCD3, isCD4, isCD5, isCD6, isCD7, isCD8, isCD9,
                     cd, cdOpinion,
                     isZD1, isZD2, isZD3, isZD4,
                     zd, zdOpinion,
                     forPPriceOpinion, forPlanOpinion,
                     forLoanOpinion, forCPriceOpinion,
                     forProgress, forProgressOpinion, transaction);
                //TODO: 九、与合同总价的关系审核:与合同总价的匹配关系核算（A+H之和与合同总价比例、工程类合同不超过85%，服务类合同不超过90%）  计算过程公式表示式及结果没有刷新

                dal1.ComputeAuditTable(id, transaction);
                transaction.Commit();
                bRet = true;
            }
            catch (Exception ex)
            {
                transaction.Rollback();
                throw ex;
            }
            finally
            {
                connection.Close();
            }
            return bRet;
        }
        /// <summary>
        /// 添加批次回执
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="batchId"></param>
        /// <param name="arrRecId"></param>
        /// <returns></returns>
        public bool AddBatchRec(string userId, string batchId, string[] arrRecId)
        {
            bool bRet = false;
            List<Bu_BatchRec> lsBatchRes = new List<Bu_BatchRec>();
            Bu_BatchRec item = null;
            foreach (string s in arrRecId)
            {
                item = new Bu_BatchRec();
                item.BatchID = batchId;
                item.ID = Honestysoft.BaseLibrary.Common.Guid.GetGuid();
                item.RecID = s;
                item.IsBack = false;
                item.IsReceive = false;
                item.IsSend = false;
                item.TableCode = Guid.NewGuid().ToString();
                item.TableID = Guid.NewGuid().ToString();
                lsBatchRes.Add(item);
            }
            Bu_BatchRec_DAL dal1 = new Bu_BatchRec_DAL(_connectionStringName);
            Bu_AuditBatch_DAL dal2 = new Bu_AuditBatch_DAL(_connectionStringName);
            DbTransaction transaction  = Honestysoft.BaseLibrary.Data.DatabaseProvider.GetDbTransaction(_connectionStringName);
            DbConnection connection  =transaction.Connection;
            try
            {
                dal1.InsertEntitys(lsBatchRes, transaction);
                dal2.CreateBatchTable(batchId, userId, transaction);
                transaction.Commit();
                bRet = true;
            }
            catch (Exception ex)
            {
                transaction.Rollback();
                throw ex;
            }
            finally
            {
                connection.Close();
            }
            return bRet;
        }

        /// <summary>
        /// 删除批次回执（同时删除生成的审核表及批次合同）
        /// </summary>
        /// <param name="batchId"></param>
        /// <param name="arrId"></param>
        /// <returns></returns>
        public bool DeleteBatchRec(string batchId, string[] arrId, DbTransaction transaction)
        {
            bool bRet = false;
            //DbTransaction transaction = Honestysoft.BaseLibrary.Data.DatabaseProvider.GetDbTransaction(_connectionStringName);
            //DbConnection connection = transaction.Connection;
            try
            {
                new Bu_BatchRec_DAL(_connectionStringName).DeleteByKey(arrId, transaction);
                new Bu_BatchContract_DAL(_connectionStringName).DeleteBatchContract(batchId, transaction);
                new Bu_AuditBatch_DAL(_connectionStringName).DeleteBatchTable(batchId, transaction);
                //transaction.Commit();
                bRet = true;
            }
            catch (Exception ex)
            {
                //transaction.Rollback();
                throw ex;
            }
            //finally
            //{ 
            //connection.Close();
            //}
            return bRet;
        }

        /// <summary>
        /// 签收作业表
        /// </summary>
        /// <param name="id"></param>
        /// <param name="date"></param>
        /// <param name="opinion"></param>
        /// <returns></returns>
        public bool ReceiveBatchRec(string id, DateTime date, string opinion)
        { 
            bool bRet = false;
            DbTransaction transaction = Honestysoft.BaseLibrary.Data.DatabaseProvider.GetDbTransaction(_connectionStringName);
            DbConnection connection = transaction.Connection;
            try
            {
                BaseBusinessLogic<Bu_BatchRec> bll1 = new BaseBusinessLogic<Bu_BatchRec>(_connectionStringName);
                BaseBusinessLogic<Bu_AuditTable> bll2 = new BaseBusinessLogic<Bu_AuditTable>(_connectionStringName);
                //签收后，要更改作业表状态及初审时间
                Bu_BatchRec rec = bll1.GetEntity(id);
                rec.IsReceive = true;
                rec.RecTime = date;
                rec.RecOpinion = opinion;
                bll1.UpdateEntity(rec, transaction);
                bll2.UpdateColumn("FirstDate", date, rec.TableID, transaction);
                bll2.UpdateColumn("BuStatus", ((int)EnumItem.AuditTableStatus.FAppr).ToString(), rec.TableID, transaction);
                transaction.Commit();
                bRet = true;
            }
            catch (Exception ex)
            {
                transaction.Rollback();
                throw ex;
            }
            finally
            {
                connection.Close();
            }
            return bRet;
        }

        /// <summary>
        /// 计算批次内部审核作业表
        /// </summary>
        /// <param name="id"></param>
        /// <param name="transaction"></param>
        /// <returns></returns>
        public int ComputeBatchTable(string id, DbTransaction transaction)
        {
            return new Bu_AuditBatch_DAL(_connectionStringName).ComputeBatchTable(id, transaction);
        }
        /// <summary>
        /// 得到最新批次内部审核作业表
        /// </summary>
        /// <returns></returns>
        public DataTable GetLastBatchAuditTable()
        {
            return new Bu_AuditTable_DAL(_connectionStringName).GetLastBatchAuditTable();
        }

        /// <summary>
        /// 检查是否能够锁定批次
        /// </summary>
        /// <param name="batchID"></param>
        /// <returns></returns>
        public int CheckCanLockBatch(string batchID)
        {
            return new Bu_AuditBatch_DAL(_connectionStringName).CheckCanLockBatch(batchID);
        }

        /// <summary>
        /// 检查是否能够锁定批次
        /// </summary>
        /// <param name="batchID"></param>
        /// <returns></returns>
        public int CheckCanOutPutBatch(string batchID)
        {
            return new Bu_AuditBatch_DAL(_connectionStringName).CheckCanOutPutBatch(batchID);
        }

        public void ToDatabase(string recID, string userID)
        {
            new Bu_DocReceive_Temp_DAL(_connectionStringName).ToDatabase(recID, userID);
        }

        /// <summary>
        /// 得到是否已有使用发票
        /// </summary>
        /// <param name="id"></param>
        /// <param name="lsNo"></param>
        /// <param name="lsCode"></param>
        /// <returns></returns>
        public DataTable GetExistsInvoice(string id, string no, string code)
        {
            return new Bu_AuditTable_Invoice_DAL(_connectionStringName).GetExistsInvoice(id, no, code);
        }
        /// <summary>
        /// 保存发票
        /// </summary>
        /// <param name="id"></param>
        /// <param name="lsInvoice"></param>
        /// <returns></returns>
        public bool SaveInvoices(string id, List<Bu_AuditTable_Invoice> lsInvoice)
        {
            bool bRet = false;
            DbTransaction transaction = Honestysoft.BaseLibrary.Data.DatabaseProvider.GetDbTransaction(_connectionStringName);
            DbConnection connection = transaction.Connection;
            try
            {
                QueryParameters query = new QueryParameters();
                query.Add("TableID", id, QueryParameters.OperatorType.Equal);
                Bu_AuditTable_Invoice_DAL dal = new Bu_AuditTable_Invoice_DAL(_connectionStringName);
                dal.Delete(query, transaction);
                dal.InsertEntitys(lsInvoice, transaction);
                transaction.Commit();
                bRet = true;
            }
            catch (Exception ex)
            {
                transaction.Rollback();
                Honestysoft.BaseLibrary.ExceptionHandling.ExceptionHelper.ExceptionDistribute(ex, false);
            }
            finally
            {
                connection.Close();
            }
            return bRet;
        }

        /// <summary>
        /// 得到放款、拨付记录
        /// </summary>
        /// <param name="batchNo"></param>
        /// <param name="projectSN"></param>
        /// <param name="projectName"></param>
        /// <param name="contractName"></param>
        /// <param name="code"></param>
        /// <param name="isGive"></param>
        /// <param name="isBF"></param>
        /// <param name="pageSize"></param>
        /// <param name="currentPageIndex"></param>
        /// <param name="pageCount"></param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        public DataTable GetBFGive(int? batchNo, string projectSN, string projectName, string contractName, string code, bool? isGive, bool? isBF, int pageSize, int currentPageIndex, out int pageCount, out int recordCount)
        {
            return new Bu_AuditTable_DAL(_connectionStringName).GetBFGive(batchNo, projectSN, projectName, contractName, code, isGive, isBF, pageSize, currentPageIndex, out pageCount, out recordCount);
        }
        /// <summary>
        /// 保存放款拨付记录
        /// </summary>
        /// <param name="lsUpdate"></param>
        /// <returns></returns>
        public bool UpdateBFGive(List<Bu_AuditTable> lsUpdate)
        {
            bool bRet = false;
            List<string> lsID = Honestysoft.BaseObject.DataMapping.GetEntitysStringPropertyList<Bu_AuditTable>(lsUpdate, "ID");
            Bu_AuditTable_DAL dal = new Bu_AuditTable_DAL(_connectionStringName);
            List<Bu_AuditTable> lsResult = dal.SelectEntitysByKey(lsID.ToArray());
            Bu_AuditTable findItem = null;
            List<string> lsProjectID = new List<string>();
            foreach (Bu_AuditTable item in lsResult)
            {
                findItem = lsUpdate.Find((Bu_AuditTable find) => find.ID == item.ID);
                item.GiveAmount = findItem.GiveAmount;
                item.GiveDate = findItem.GiveDate;
                item.BFAmount = findItem.BFAmount;
                item.BFDate = findItem.BFDate;
                item.IsGive = false;
                item.IsBF = false;
                if (item.GiveAmount > 0 || item.GiveDate.HasValue)
                {
                    item.IsGive = true;
                }
                if (item.BFAmount > 0 || item.BFDate.HasValue)
                {
                    item.IsBF = true;
                }
                lsProjectID.Add(item.ProjectID);
            }            
            //刷新受影响作业表
            Bu_AuditTable_DAL dal2 = new Bu_AuditTable_DAL(_connectionStringName);
            DataTable dt = dal2.GetMaxBatchAuditTableByProject(lsProjectID.ToArray());
            DbTransaction transaction = Honestysoft.BaseLibrary.Data.DatabaseProvider.GetDbTransaction(_connectionStringName);
            DbConnection connection = transaction.Connection;
            try
            {
                dal.UpdateEntitys(lsResult, transaction);
                foreach (DataRow dr in dt.Rows)
                {
                    dal2.RefreshAuditTable(dr["ID"].ToString(), transaction);
                }
                foreach (DataRow dr in dt.Rows)
                {
                    dal2.ComputeAuditTable(dr["ID"].ToString(), transaction);
                }
                transaction.Commit();
                bRet = true;
            }
            catch (Exception ex)
            {
                transaction.Rollback();
                throw ex;
            }
            finally
            {
                connection.Close();
            }
            return bRet;
        }

        /// <summary>
        /// 删除首次新增的回执
        /// </summary>
        /// <param name="arrID"></param>
        /// <returns></returns>
        public bool DeleteDocReceiveTemp(string[] arrID, DbTransaction transaction)
        {
            DeleteDocReceive(arrID, transaction);
            new Bu_DocReceive_Temp_DAL(_connectionStringName).DeleteByKey(arrID, transaction);
            return true;
        }
        /// <summary>
        /// 删除回执
        /// </summary>
        /// <param name="arrID"></param>
        /// <returns></returns>
        public bool DeleteDocReceive(string[] arrID,DbTransaction transaction)
        {
            //删除回执产生的作业表
            new Bu_AuditTable_DAL(_connectionStringName).DeleteByRecID(arrID,transaction);
            //删除批次回执
            new Bu_BatchRec_DAL(_connectionStringName).DeleteByRecID(arrID,transaction);
            //删除批次合同
            new Bu_BatchContract_DAL(_connectionStringName).DeleteByRecID(arrID,transaction);
            //删除回执
            new Bu_DocReceive_DAL(_connectionStringName).DeleteByKey(arrID, transaction);
            return true;
        }

        /// <summary>
        /// 按合同统计申请笔数及申请金额
        /// </summary>
        /// <param name="contractId"></param>
        /// <returns></returns>
        public DataTable GetSumAmountDocRecByContract(string contractId)
        {
            return new Bu_DocReceive_DAL(_connectionStringName).GetSumAmountDocRecByContract(contractId);
        }

        /// <summary>
        /// 按合同统计初审笔数及初审金额
        /// </summary>
        /// <param name="contractId"></param>
        /// <returns></returns>
        public DataTable GetSumAmount_S_ByContract(string contractId)
        {
            return new Bu_DocReceive_DAL(_connectionStringName).GetSumAmount_S_ByContract(contractId);
        }

         /// <summary>
        /// 根据项目的到初审金额
        /// </summary>
        /// <param name="projectId"></param>
        /// <param name="date"></param>
        /// <returns></returns>
        public decimal GetAmountSByProject(string projectId, DateTime date)
        {
            return new Bu_AuditTable_DAL(_connectionStringName).GetAmountSByProject(projectId, date);
        }

        ///// <summary>
        ///// 得到发改委返回的资金支付汇总表
        ///// </summary>
        ///// <param name="batchNo"></param>
        ///// <param name="pageSize"></param>
        ///// <param name="currentPageIndex"></param>
        ///// <param name="recordCount"></param>
        ///// <returns></returns>
        //public DataTable GetFGWList(int batchNo, int pageSize, int currentPageIndex, out int recordCount)
        //{
        //    return new Bu_AuditTable_FGW_DAL(_connectionStringName).GetFGWList(batchNo, pageSize, currentPageIndex, out recordCount);
        //}


        /// <summary>
        /// 得到可新增支付汇总表（发改委）的批次
        /// 说明：必须生成过支付汇总表（深超报送给发改委）并且未完成支付汇总表（发改委）的批次
        /// </summary>
        /// <returns></returns>
        public DataTable GetFGWBatch()
        {
            return new Bu_BatchSummary_DAL(_connectionStringName).GetFGWBatch();
        }
        /// <summary>
        /// 得到可选择的作业表
        /// </summary>
        /// <param name="batchNo"></param>
        /// <returns></returns>
        public DataTable GetFWGSelectAT(string batchID)
        {
            Bu_BatchSummary batchSummary = new Bu_BatchSummary_DAL(_connectionStringName).SelectEntityByKey(batchID);
            //DateTime? rptDate=null;
            //if (batchSummary != null)
            //{
            //    rptDate = batchSummary.PrintDate;
            //}
            //else
            //{
            //    rptDate = Convert.ToDateTime("1900-01-01");
            //}
            DataTable dtRet = new Bu_AuditTable_FGW_DAL(_connectionStringName).GetFWGSelectAT(batchSummary.BatchNo);
            DataTable dtSelected = new Bu_AuditTable_FGW_DAL(_connectionStringName).GetFGWSelectedAT(batchSummary.BatchNo);
            for (int i = dtRet.Rows.Count - 1; i >= 0; i--)
            {
                if (dtSelected.Select("ATID='" + dtRet.Rows[i]["ID"].ToString() + "'").Length > 0)
                {
                    dtRet.Rows.RemoveAt(i);
                }
            }
            return dtRet;
        }
        

        public Bu_AuditTable_FGW GetEditFGW(string id)
        {
            Bu_AuditTable_FGW_DAL fgwDal = new Bu_AuditTable_FGW_DAL(_connectionStringName);
            Bu_AuditTable_FGWDetail_DAL detailDal = new Bu_AuditTable_FGWDetail_DAL(_connectionStringName);
            Bu_AuditTable_FGW retItem = fgwDal.SelectEntityByKey(id);
            retItem.BatchSummary = new BaseBusinessLogic<Bu_BatchSummary>().GetEntity(retItem.BatchID);
            retItem.BatchSummaryDetail = fgwDal.GetFWGSelectAT(retItem.BatchSummary.BatchNo);
            QueryParameters query = new QueryParameters();
            query.Add("BatchID", retItem.BatchID, QueryParameters.OperatorType.Equal);
            query.Add("Counter", retItem.Counter, QueryParameters.OperatorType.Small);
            OrderParameters order = new OrderParameters();
            order.Add("Counter");
            retItem.PriorFGW = fgwDal.SelectEntitys(query, order); //必须
            if (retItem.PriorFGW != null && retItem.PriorFGW.Count > 0)
            {
                query = new QueryParameters();
                query.Add("FGWID", Honestysoft.BaseObject.DataMapping.GetEntitysStringPropertyList<Bu_AuditTable_FGW>(retItem.PriorFGW, "ID"), QueryParameters.OperatorType.IN);
                retItem.PriorFGWDetail = detailDal.Select(query); //必须
            }
            query = new QueryParameters();
            query.Add("FGWID", retItem.ID, QueryParameters.OperatorType.Equal);
            retItem.ThisTimeAT = detailDal.Select(query);
            return retItem;
        }
        /// <summary>
        /// 得到新的发改委资金支付汇总表
        /// </summary>
        /// <param name="batchID"></param>
        /// <returns></returns>
        public Bu_AuditTable_FGW GetNewFGW(string batchID)
        {
            Bu_AuditTable_FGW_DAL fgwDal = new Bu_AuditTable_FGW_DAL(_connectionStringName);
            Bu_AuditTable_FGWDetail_DAL detailDal = new Bu_AuditTable_FGWDetail_DAL(_connectionStringName);
            Bu_AuditTable_FGW retItem = new Bu_AuditTable_FGW(); //必须
            retItem.BatchSummary = new Bu_BatchSummary_DAL(_connectionStringName).SelectEntityByKey(batchID);  //必须         
            retItem.BatchSummaryDetail = fgwDal.GetFWGSelectAT(retItem.BatchSummary.BatchNo); //必须
            QueryParameters query = new QueryParameters();
            query.Add("BatchID", batchID, QueryParameters.OperatorType.Equal);
            OrderParameters order = new OrderParameters();
            order.Add("Counter");
            retItem.PriorFGW = fgwDal.SelectEntitys(query, order); //必须
            retItem.ThisTimeAT = detailDal.NewTable();
            if (retItem.PriorFGW != null && retItem.PriorFGW.Count > 0)
            {
                query = new QueryParameters();
                query.Add("FGWID", Honestysoft.BaseObject.DataMapping.GetEntitysStringPropertyList<Bu_AuditTable_FGW>(retItem.PriorFGW, "ID"), QueryParameters.OperatorType.IN);
                retItem.PriorFGWDetail = detailDal.Select(query); //必须
                retItem.Counter = retItem.PriorFGW[retItem.PriorFGW.Count - 1].Counter + 1;
            }
            else
            {
                retItem.Counter = 1;
            }
            retItem.BatchID = batchID;
            retItem.ID = Honestysoft.BaseLibrary.Common.Guid.GetGuid();
            retItem.PrintDate = DateTime.Today;
            retItem.Creator = "深超公司";
            return retItem;
        }

        /// <summary>
        /// 添加新选择的作业表
        /// </summary>
        /// <param name="arrID"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        public Bu_AuditTable_FGW AddFGWDetail(string[] arrATID, Bu_AuditTable_FGW item)
        {
            if (arrATID == null || arrATID.Length == 0) { return item; }
            Bu_AuditTable_FGW newItem = item;
            QueryParameters query = new QueryParameters();
            query.Add("ID", arrATID, QueryParameters.OperatorType.IN);
            DataTable dtAT = new Bu_AuditTable_DAL(_connectionStringName).Select(query);
            DataRow drNew=null,drBatchSummary=null;
            decimal amount_C_S = 0, amount_docRec_S = 0, tAmount_C_A_S = 0, amount_S = 0, p_DocRec = 0, p_S = 0;
            string contractCategory="";
            DataTable dtATOpinion = new Bu_AuditTable_Opinion_DAL(_connectionStringName).Select(query);
            foreach (string atId in arrATID)
            {
                drNew = newItem.ThisTimeAT.NewRow();
                drNew["ID"] = Honestysoft.BaseLibrary.Common.Guid.GetGuid();
                drNew["FGWID"] = newItem.ID;
                drNew["ATID"] = atId;
                contractCategory=dtAT.Select("ID='" + atId + "'")[0]["ContractCategory"].ToString();
                drBatchSummary = newItem.BatchSummaryDetail.Select("ID='" + atId + "'")[0];
                amount_C_S = Convert.ToDecimal(drBatchSummary["Amount_C_S"]);
                amount_docRec_S = Convert.ToDecimal(drBatchSummary["Amount_docRec_S"]);
                tAmount_C_A_S = Convert.ToDecimal(drBatchSummary["TAmount_C_A_S"]);
                amount_S = Convert.ToDecimal(drBatchSummary["Amount_S"]);
                p_DocRec = (amount_C_S == 0 ? 0 : (amount_docRec_S + tAmount_C_A_S) / amount_C_S);
                p_S = (amount_C_S == 0 ? 0 : (amount_S + tAmount_C_A_S) / amount_C_S);
                if (contractCategory == "10031502")//施工类85%
                {
                    //if (Convert.ToDouble(p_DocRec) >= 0.85 && amount_docRec_S > amount_S)//如果申请超出规定，审核未超出，则要提示“支付至合同价的%”
                    //{
                    //    //drNew["Opinion"] = "按发改委规定支付至合同价的85%";//改为采用审核员意见
                    //    drNew["Opinion"] = dtATOpinion.Select("ID='" + atId + "'")[0]["ForCPriceOpinion"].ToString();
                    //}
                    //else
                    //{
                    //    drNew["Opinion"] = "经市发改委审核，同意支付";
                    //}
                    //再改为只要初审超过就引用
                    if (Convert.ToDouble(p_S) >= 0.85)
                    {
                        drNew["Opinion"] = dtATOpinion.Select("ID='" + atId + "'")[0]["ForCPriceOpinion"].ToString();
                    }
                    else
                    {
                        drNew["Opinion"] = "经市发改委审核，同意支付";
                    }
                }
                else if (contractCategory == "10031503")//服务类90%
                {
                    //if (Convert.ToDouble(p_S) >= 0.9 && amount_docRec_S > amount_S)
                    //{
                    //    //drNew["Opinion"] = "按发改委规定支付至合同价的90%";//改为采用审核员意见

                    //    drNew["Opinion"] = dtATOpinion.Select("ID='" + atId + "'")[0]["ForCPriceOpinion"].ToString();
                    //}
                    //else
                    //{
                    //    drNew["Opinion"] = "经市发改委审核，同意支付";
                    //}

                    //再改为只要初审超过就引用
                    if (Convert.ToDouble(p_S) >= 0.9)
                    {
                        drNew["Opinion"] = dtATOpinion.Select("ID='" + atId + "'")[0]["ForCPriceOpinion"].ToString();
                    }
                    else
                    {
                        drNew["Opinion"] = "经市发改委审核，同意支付";
                    }
                }
                else
                {
                    drNew["Opinion"] = "经市发改委审核，同意支付";
                }
                newItem.ThisTimeAT.Rows.Add(drNew);
            }
            newItem.ResetSelectedAT();
            return newItem;
        }
        ///// <summary>
        ///// 刷新备注2文本
        ///// </summary>
        ///// <param name="sourceItem"></param>
        ///// <returns></returns>
        //public Bu_AuditTable_FGW RefreshFGWRemark2(Bu_AuditTable_FGW sourceItem)
        //{
        //    Bu_AuditTable_FGW newItem = sourceItem;
        //    if (newItem.LastSumCount + newItem.dtDetail.Rows.Count == newItem.dtSummary.Rows.Count)
        //    {
        //        newItem.Remark2 = newItem.LastRemark2 + newItem.PrintDate.ToString("yyyy年M月d日") + "经市发改委审核后同意支付"+ (newItem.Counter == 1 ? "" :"剩余的") + newItem.CurrentProjectCount.ToString() + "个项目、" + newItem.CurrentContractCount.ToString() + "份合同、金额" + string.Format("{0:N}", newItem.CurrentATAmount_S) + "元。";
        //        newItem.Remark2 += "（本批次支付完毕）";
        //    }
        //    else
        //    {
        //        newItem.Remark2 = newItem.LastRemark2 + newItem.PrintDate.ToString("yyyy年M月d日") + "经市发改委审核后同意支付" + newItem.CurrentProjectCount.ToString() + "个项目、" + newItem.CurrentContractCount.ToString() + "份合同、金额" + string.Format("{0:N}", newItem.CurrentATAmount_S) + "元。";
        //    }
        //    return newItem;
        //}
        /// <summary>
        /// 删除发改委支付汇总表导入的作业表
        /// </summary>
        /// <param name="arrATID"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        public Bu_AuditTable_FGW DeleteFGWDetail(string[] arrATID, Bu_AuditTable_FGW item)
        {
            if (arrATID == null || arrATID.Length == 0) { return item; }
            Bu_AuditTable_FGW newItem = item;
            List<string> lsATID = new List<string>(arrATID);
            for (int i = newItem.ThisTimeAT.Rows.Count - 1; i >= 0; i--)
            {
                if (lsATID.Contains(newItem.ThisTimeAT.Rows[i]["ATID"].ToString()))
                {
                    newItem.ThisTimeAT.Rows.RemoveAt(i);
                }
            }
            //for (int i = newItem.dtDetail.Rows.Count - 1; i >= 0; i--)
            //{
            //    if (lsATID.Contains(newItem.dtDetail.Rows[i]["ID"].ToString()))
            //    {
            //        newItem.dtDetail.Rows.RemoveAt(i);
            //    }
            //}
            //newItem = RefreshFGWRemark2(newItem);

            newItem.ResetSelectedAT();
            return newItem;
        }

        /// <summary>
        /// 保存发改委支付汇总表
        /// </summary>
        /// <param name="item"></param>
        public void SaveFGW(Bu_AuditTable_FGW item)
        {
            Bu_AuditTable_FGW_DAL fgwDal = new Bu_AuditTable_FGW_DAL(_connectionStringName);
            Bu_AuditTable_FGWDetail_DAL detailDal = new Bu_AuditTable_FGWDetail_DAL(_connectionStringName);
            DbTransaction transaction = Honestysoft.BaseLibrary.Data.DatabaseProvider.GetDbTransaction(_connectionStringName);
            DbConnection connection = transaction.Connection;

            bool isExists = fgwDal.IsExists(item.ID);

            if (!isExists)//创建
            {                
                try
                {
                    fgwDal.InsertEntity(item, transaction);
                    detailDal.Insert(item.ThisTimeAT, transaction);
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    Honestysoft.BaseLibrary.ExceptionHandling.ExceptionHelper.ExceptionDistribute(ex, false);
                    throw new Honestysoft.BaseLibrary.ExceptionHandling.BaseException("创建支付汇总表失败！");
                }
                finally
                {
                    connection.Close();
                }
            }
            else //修改(如果修改了导入的作业表数量，要重新检查完成标识”)
            {
                
                try
                {
                    //检查是否存在"（本批次支付完毕）"但是作业表未全部完成的记录
                    //本身的记录数加上其他已保存到数据库的作业表的记录数，如果少于深超汇总表的记录数，则去除IsEnd标志
                    DataTable dtOtherAT = detailDal.GetOtherCounterAT(item.BatchID, item.Counter);
                    fgwDal.UpdateEntity(item, transaction);
                    if (dtOtherAT.Rows.Count + item.ThisTimeAT.Rows.Count < item.BatchSummaryDetail.Rows.Count)
                    {
                        fgwDal.SetBatchIsEnd(false, item.BatchID, transaction);
                    }
                    //先删除，再插入
                    QueryParameters query = new QueryParameters();
                    query.Add("FGWID", item.ID, QueryParameters.OperatorType.Equal);
                    detailDal.Delete(query, transaction);
                    //此处不能直接用item.ThisTimeAT来进行新增，因为是查询出来的，行状态有些不是Insert状态                    
                    List<Bu_AuditTable_FGWDetail> lsInsert = new List<Bu_AuditTable_FGWDetail>();
                    Bu_AuditTable_FGWDetail insertItem = null;
                    foreach (DataRow dr in item.ThisTimeAT.Rows)
                    {
                        insertItem = new Bu_AuditTable_FGWDetail();
                        insertItem.ATID = dr["ATID"].ToString();
                        insertItem.FGWID = item.ID;
                        insertItem.ID = Guid.NewGuid().ToString();
                        insertItem.Opinion = dr["Opinion"].ToString();
                        lsInsert.Add(insertItem);
                    }
                    detailDal.InsertEntitys(lsInsert, transaction);                    
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    Honestysoft.BaseLibrary.ExceptionHandling.ExceptionHelper.ExceptionDistribute(ex, false);
                    throw new Honestysoft.BaseLibrary.ExceptionHandling.BaseException("修改支付汇总表失败！");
                }
                finally
                {
                    connection.Close();
                }
            }
        }

        /// <summary>
        /// 得到同批次不同支付次数的其他汇总表的明细记录
        /// </summary>
        /// <param name="batchID"></param>
        /// <param name="thisCounter"></param>
        /// <returns></returns>
        public DataTable GetOtherCounterAT(string batchID, int thisCounter)
        {
            return new Bu_AuditTable_FGWDetail_DAL(_connectionStringName).GetOtherCounterAT(batchID, thisCounter);
        }

        /// <summary>
        /// 得到批次报送时间
        /// </summary>
        /// <returns></returns>
        public DataTable GetBatchReportDate()
        {
            return new Bu_BatchSummary_DAL(_connectionStringName).GetBatchReportDate();
        }
    }
}
